其他
2个基础操作案例带你入门MySQL
导读:MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle旗下产品。MySQL是最流行的关系型数据库管理系统之一,许多全球规模庞大、发展迅速的组织,Facebook、Google、Adobe、Alcatel Lucent和Zappos等都依靠MySQL来管理数据,为其高容量网站、关键业务系统和套装软件提供支持。
数据定义语句(Data Definition Statement) 数据处理语句(Data Manipulation Statement) 事务和锁定声明(Transactional and Locking Statement) 复制语句(Replication Statement) 预处理SQL语句语法(Prepared SQL Statement Syntax) 复合语句语法(Compound-Statement Syntax) 数据库管理声明(Database Administration Statement) 效用声明(Utility Statement)
mysql> CREATE TABLESPACE ts_1 ADD DATAFILE 'ts_1.ibd' Engine=InnoDB;
Query OK, 0 rows affected (0.11 sec)
mysql> CREATE DATABASE testq;
Query OK, 1 row affected (0.00 sec)
mysql> use testq;
Database changed
mysql> CREATE TABLE t1(
-> c1 INT STORAGE DISK,# 数据存储于磁盘
-> c2 INT STORAGE MEMORY# 数据基于内存
-> ) TABLESPACE ts_1 ENGINE INNODB;# 指定表空间ts_1及引擎INNODB
Query OK, 0 rows affected (0.34 sec)
mysql> ALTER TABLE t1 ADD c3 VARCHAR(10);
Query OK, 0 rows affected (0.52 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> DESC t1;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| c1 | int(11) | YES | | NULL | |
| c2 | int(11) | YES | | NULL | |
| c3 | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
注意
mysql> INSERT INTO t1(c1,c2,c3) VALUES(1,c1*2,'a'),(2,c1*2,'b');
Query OK, 2 rows affected (0.10 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM t1;
+------+------+------+
| c1 | c2 | c3 |
+------+------+------+
| 1 | 2 | a |
| 2 | 4 | b |
+------+------+------+
2 rows in set (0.00 sec)
mysql> UPDATE t1 SET c2=c1*3,c3='updateb'
-> WHERE c1=2;
Query OK, 1 row affected (0.11 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> SELECT * FROM t1 WHERE c1=2;
+------+------+---------+
| c1 | c2 | c3 |
+------+------+---------+
| 2 | 6 | updateb |
+------+------+---------+
1 row in set (0.05 sec)
mysql> DELETE FROM t1 WHERE c1=2;
Query OK, 1 row affected (0.10 sec)
mysql> SELECT * FROM t1;
+------+------+------+
| c1 | c2 | c3 |
+------+------+------+
| 1 | 2 | a |
+------+------+------+
1 row in set (0.00 sec)
本文摘编自《大数据管理系统原理与技术》,经出版方授权发布。
长按二维码了解及购买转载请联系微信:DoctorData
有话要说👇
Q: 关于MySQL,你还想了解哪些知识点?
欢迎留言与大家分享
猜你想看👇